package com.yfp.system.controller;

import com.yfp.common.core.utils.poi.ExcelUtil;
import com.yfp.common.core.web.controller.BaseController;
import com.yfp.common.core.web.domain.AjaxResult;
import com.yfp.common.core.web.page.TableDataInfo;
import com.yfp.common.log.annotation.Log;
import com.yfp.common.log.enums.BusinessType;
import com.yfp.common.security.annotation.InnerAuth;
import com.yfp.system.api.domain.SysOperLog;
import com.yfp.system.domain.SysOperationLog;
import com.yfp.system.service.ISysOperLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 操作日志记录
 * 
 *
 */
@RestController
@RequestMapping("/operlog")
@Tag(name = "操作日志管理")
public class SysOperlogController extends BaseController
{
    @Autowired
    private ISysOperLogService operLogService;

    @GetMapping("/list")
    @Operation(summary = "操作日志列表")
    public TableDataInfo list(SysOperLog operLog)
    {
        startPage();
        List<SysOperLog> list = operLogService.selectOperLogList(operLog);
        return getDataTable(list);
    }

    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "操作日志导出")
    public void export(HttpServletResponse response, SysOperLog operLog)
    {
        List<SysOperLog> list = operLogService.selectOperLogList(operLog);
        ExcelUtil<SysOperLog> util = new ExcelUtil<SysOperLog>(SysOperLog.class);
        util.exportExcel(response, list, "操作日志");
    }

    @Log(title = "操作日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{operIds}")
    @Operation(summary = "操作日志删除")
    public AjaxResult remove(@PathVariable Long[] operIds)
    {
        return toAjax(operLogService.deleteOperLogByIds(operIds));
    }

    @Log(title = "操作日志", businessType = BusinessType.CLEAN)
    @DeleteMapping("/clean")
    @Operation(summary = "操作日志清空")
    public AjaxResult clean()
    {
        operLogService.cleanOperLog();
        return success();
    }

    @InnerAuth
    @PostMapping("save")
    @Operation(summary = "新增操作日志")
    public AjaxResult add(@RequestBody SysOperLog operLog)
    {
        return toAjax(operLogService.insertOperlog(operLog));
    }


    @InnerAuth
    @PostMapping("/addOperationLog")
    @Operation(summary = "新增其他日志")
    public AjaxResult addOperationLog(@RequestBody SysOperationLog sysOperationLog)
    {
        return toAjax(operLogService.addOperationLog(sysOperationLog));
    }

    @GetMapping("/operationLogList")
    @Operation(summary = "其他日志列表")
    public TableDataInfo operationLogList(SysOperationLog sysOperationLog) {
        startPage();
        List<SysOperationLog> sysOperationLogs = operLogService.operationLogList(sysOperationLog);
        return getDataTable(sysOperationLogs);
    }

}
